const express = require('express');
const router = express.Router();
const fieldTypeController = require('../controllers/fieldTypeController');
const { auth, authorize } = require('../middleware/auth');
const { auditLogger } = require('../middleware/audit');

// 应用认证中间件到所有路由
router.use(auth);

// 获取字段类型列表
router.get('/', 
  fieldTypeController.getFieldTypes
);

// 获取字段类型详情
router.get('/:type', 
  fieldTypeController.getFieldType
);

// 验证字段值
router.post('/:type/validate', 
  fieldTypeController.validateFieldValue
);

// 创建字段类型（仅管理员）
router.post('/', 
  authorize('admin'),
  auditLogger('create', 'fieldType'),
  fieldTypeController.createFieldType
);

// 更新字段类型（仅管理员）
router.put('/:type', 
  authorize('admin'),
  auditLogger('update', 'fieldType'),
  fieldTypeController.updateFieldType
);

module.exports = router;